<extend name="Base/common" />
<block name="body">
	<style type="text/css">
    .option_form label{ display:inline-block; width:80px; margin:5px;}
    </style>
  <div class="span9 page_message">
    <section id="contents"> 
      <include file="Addons/_nav" /> 
      <if condition="$add_button || $del_button || $search_button || !empty($top_more_button)">   
      <div class="table-bar">
        <div class="fl">
          <empty name="model.extend">
			<div class="tools">
				<if condition="$add_button"><php> $add_url || $add_url = U('add?model='.$model['id'], $get_param);</php><a class="btn" href="{$add_url}">新 增</a></if>
				<if condition="$del_button"><php> $del_url || $del_url = U('del?model='.$model['id'], $get_param);</php><button class="btn ajax-post confirm" target-form="ids" url="{$del_url}">删 除</button></if>    
                <volist name="top_more_button" id="vo">
                <if condition="$vo[is_buttion]">
                <button class="btn {$vo.class}" target-form="ids" url="{$vo.url}">{$vo.title}</button>
                <else />
                <a class="btn" href="{$vo.url}">{$vo.title}</a>
                </if>
                &nbsp;
                </volist>            
			</div>
          </empty>
          
        </div>
        <!-- 高级搜索 -->
        <if condition="$search_button">
        <div class="search-form fr cf">
          <div class="sleft" style="margin-right:10px">
           <input style="width:100px;" type="text" name="number" class="search-input" value="{:$_GET['number']}" placeholder="请输入会员卡号">
            <a class="sch-btn" href="javascript:;" id="number_search" url="{:U('lists?model='.$model['id'],array('mdm'=>$_GET['mdm']))}"><i class="btn-search"></i></a> 
           </div>
           <div class="sleft" style="margin-right:10px">
           
            <input style="width:100px;" type="text" name="phone" class="search-input" value="{:$_GET['phone']}" placeholder="请输入手机号">
            <a class="sch-btn" href="javascript:;" id="phone_search" url="{:U('lists?model='.$model['id'],array('mdm'=>$_GET['mdm']))}"><i class="btn-search"></i></a> 
            </div>
           <div class="sleft">
          
            <php> $get_param[model]=$model['name']; $search_url || $search_url = addons_url($_REQUEST ['_addons'].'://'.$_REQUEST ['_controller'].'/lists', $get_param);</php>
            <php>empty($search_key) && $search_key=$model['search_key'];empty($search_key) && $search_key='title';</php>
            <input style="width:100px" type="text" name="{$search_key}" class="search-input" value="{:I($search_key)}" placeholder="{$placeholder}">
            <a class="sch-btn" href="javascript:;" id="search" url="{$search_url}"><i class="btn-search"></i></a> 
            </div>
        </div>
        </if>
        <!-- 多维过滤 -->
        <notempty name="muti_search">
        <form class="muti_search cf">
          <div class="" style="line-height: 30px;">
          <volist name='muti_search' id='vo'>
          <switch name="vo.type">
                <case value="select">
                    <span>{$vo.title}：</span>
                    <select name="{$vo.name}" class="search-input input-small">
                    <volist name='vo.options' id='option'>
                    <option value="{$option.value}" <eq name='option.default_value' value='option.value'>selected</eq> >{$option.title}</option>
                    </volist>                    
                    </select>
                </case>
                <case value="datetime">
                    <span>{$vo.title}：</span>
             <input type="datetime" name="start_time" class="search-input date input-small" value="{$vo.start_time}" placeholder="请选择时间">
             <span>至</span>
             <input type="datetime" name="end_time" class="search-input date input-small" value="{$vo.end_time}" placeholder="请选择时间">
                </case>
                <case value="checkbox">
                    <span>{$vo.title}：</span>
                    <volist name='vo.options' id='option'>
                    <input type="checkbox" name="{$option.name}" class="" value="{$option.value}" <eq name='option.default_value' value='option.value'>checked</eq> >{$option.title}
                    </volist>
                </case>
                <case value="radio">
                    <span>{$vo.title}：</span>
                    <volist name='vo.options' id='option'>
                    <input type="radio" name="{$option.name}" class="" value="{$option.value}" <eq name='option.default_value' value='option.value'>checked</eq> >{$option.title}
                    </volist>
                </case>
                  
             
            </switch>
            </volist>
             
             <!-- <a class="sort " href="#" title="排序">排序:高->低</a> -->
             <button type="button" class="sch-btn btn" href="javascript:;" id="search">搜索</button> </div>
        </form>
        </notempty>
      </div>
      </if>
      <!-- 数据列表 -->
      <div class="data-table">
        <div class="table-striped">
          <table cellspacing="1">
            <!-- 表头 -->
            <thead>
              <tr>
                <if condition="$check_all"><th class="row-selected row-selected"> <input type="checkbox" id="checkAll" class="check-all regular-checkbox"><label for="checkAll"></label></th></if>
                <volist name="list_grids" id="field">
                  <th <notempty name="field.width">width="{$field.width}%"</notempty> >{$field.title}</th>
                </volist>
              </tr>
            </thead>
            
            <!-- 列表 -->
            <tbody>
              <volist name="list_data" id="data">
                <tr>
                  <if condition="$check_all"><td><input class="ids regular-checkbox" type="checkbox" value="{$data['id']}" name="ids[]" id="check_{$data['id']}"><label for="check_{$data['id']}"></label></td></if>
<!--                   <volist name="list_grids" id="grid"> -->
<!--                     <td>{:get_list_field($data,$grid,$model)}</td> -->
<!--                   </volist> -->
							<td>{$data.number}</td>
							<td>{$data.username}</td>
							<td>{$data.phone}</td>
							<td>{$data.score}</td>
							<td>{$data.recharge}</td>
							<td>{$data.level}</td>
							<td>{$data.cTime|time_format}</td>
							<td>{$data.status|get_name_by_status}</td>
							<td>
								<a target="_self" href="{:U('edit?model='.$model['id'],array('id'=>$data['id']))}">编辑</a>
								<a target="confirm" href="{:U('del?model='.$model['id'],array('id'=>$data['id']))}">删除</a>
								<a onClick="$.WeiPHP.openSubmitDialog('会员充值','{:U('do_recharge?model='.$model['id'],array('id'=>$data['id']))}',600,400)" href="javascript:;">会员充值</a>
								<a onClick="$.WeiPHP.openSubmitDialog('会员消费','{:U('do_buy?model='.$model['id'],array('id'=>$data['id']))}',600,560)" href="javascript:;">会员消费</a>
								<a onClick="$.WeiPHP.openSubmitDialog('手动修改积分','{:U('update_score?model='.$model['id'],array('id'=>$data['id']))}',600,400)" href="javascript:;">手动修改积分</a>
							</td>
                	</tr>
              </volist>
            </tbody>
          </table>
        </div>
      </div>
      <div class="page"> {$_page|default=''} </div>
    </section>
  </div>
</block>
<block name="script"> 
<script type="text/javascript">
$(function(){
	//搜索功能
	$("#search,#phone_search,#number_search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
        if(query == '' ){
        	var addon="{$_REQUEST ['_addons']}";
        	if(addon){
        		url="{:addons_url($_REQUEST ['_addons'].'://'.$_REQUEST ['_controller'].'/lists')}&mdm={$_GET['mdm']}";
        	}
        }
		window.location.href = url;
	});

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });
	
    $('.export_member').click(function(){
		var ids = new Array();
		$('input[name="ids[]"]').each(function(index, element) {
            if($(this).prop('checked')){
				ids.push($(this).val());
			}
        });
		var $html = $('<form class="option_form" style="padding:20px">'+
			'<input type="hidden" value="'+ids.toString()+'" name="ids"/>'+
			'<label><input type="checkbox" name="check_option_all"/>全部选择</label><br/>'+
			'<label><input type="checkbox" name="names[]" value="number"/>卡号</label>'+
			'<label><input type="checkbox"  name="names[]"  value="username"/>姓名</label>'+
			'<label><input type="checkbox"  name="names[]"  value="phone"/>手机号</label>'+
			'<label><input type="checkbox"  name="names[]"  value="score"/>积分</label>'+
			'<label><input type="checkbox"  name="names[]"  value="recharge"/>余额</label>'+
			'<label><input type="checkbox"  name="names[]"  value="cTime"/>加入时间</label>'+
			'<label><input type="checkbox"  name="names[]"  value="status"/>状态</label>'+
			'<label><input type="checkbox"  name="names[]"  value="level"/>会员等级</label>'+
			'<br/><br/><a href="javascript:;" class="btn">确定</a></form>');
    	$.Dialog.open('选择导出的信息',{width:600,height:340},$html);
		$('input[name="check_option_all"]',$html).click(function(){
			if($(this).prop('checked')){
				$('input[name="names[]"]').prop('checked',true);
			}else{
				$('input[name="names[]"]').prop('checked',false);
			}
		})
		$('.btn',$html).click(function(){
			var url = $('.export_member').attr('url') +'&'+$('.option_form').serialize();
// 			alert(url);
			location.href=url;
// 			$.post(url,$('.option_form').serialize(),function(data){
// 				if(data.status){
				
// 				}else{
					
// 				}
// 			});
		})
		return false;
    });
})
</script> 
</block>
